package com.example.chapter11;


import java.util.function.Function;

/*
 * 11.2.6.函数组合
 * Function组合
 * */
public class Demo06 {


    public static void compose(){
        Function<Integer, Integer> multiply = (value) -> value * 2;
        Function<Integer, Integer> add      = (value) -> value + 3;

        Function<Integer, Integer> addThenMultiply = multiply.compose(add);

        Integer result1 = addThenMultiply.apply(3);
        System.out.println(result1);
    }

    public static void andThen(){
        Function<Integer, Integer> multiply = (value) -> value * 2;
        Function<Integer, Integer> add      = (value) -> value + 3;

        Function<Integer, Integer> multiplyThenAdd = multiply.andThen(add);

        Integer result2 = multiplyThenAdd.apply(3);
        System.out.println(result2);
    }


    public static void main(String[] args) {
        compose();

        andThen();
    }

}
